﻿#include "LoginPageScene.h"
#include "constant.h"
#include "Scene0917.h"
#pragma execution_character_set("utf-8")

Scene *LoginPageScene::createScene()
{
	return LoginPageScene::create();
}

bool LoginPageScene::init()
{
	if (!Scene::init())
	{
		return false;
	}
	//背景
	auto background = Sprite::create("res/Background.png");
	background->setPosition(VISIBLE_SIZE.width / 2, VISIBLE_SIZE.height / 2);
	addChild(background);

	//人物
	auto human = Sprite::create("res/denglu2.png");
	human->setPosition(VISIBLE_SIZE.width / 5, VISIBLE_SIZE.height / 2);
	human->setScale(0.5);
	addChild(human);

	//底部红条
	auto bottom = Sprite::create("res/denglu1.png");
	bottom->setPosition(VISIBLE_SIZE.width / 2, bottom->getBoundingBox().size.height / 2);
	addChild(bottom);

	//注册登录背景
	auto loginbackground = Sprite::create("res/denglu3.png");
	loginbackground->setPosition(VISIBLE_SIZE.width*0.7, VISIBLE_SIZE.height / 2.5);
	addChild(loginbackground);

	//返回按钮
	auto backBtn = Button::create("res/denglu8.png");
	backBtn->setScale(0.5);
	backBtn->setPosition(Vec2(
		(loginbackground->getPositionX()
			+ loginbackground->getBoundingBox().size.width / 2
			- backBtn->getBoundingBox().size.width / 2)*0.97,
			(loginbackground->getPositionY()
				+ loginbackground->getBoundingBox().size.height / 2
				- backBtn->getBoundingBox().size.height / 2)*0.95
	));
	addChild(backBtn);

	//注册、登录文本
	auto title = Label::createWithTTF("注册、登录", "fonts/FZCY_GBK.ttf", 42);
	title->setPosition(loginbackground->getPositionX(), backBtn->getPositionY());
	addChild(title);

	//♣
	auto plum_blossom = Sprite::create("res/denglu4.png");
	plum_blossom->setPosition(loginbackground->getPositionX() - loginbackground->getBoundingBox().size.width / 2
		+ plum_blossom->getBoundingBox().size.width + 30, backBtn->getPositionY() - 100);
	addChild(plum_blossom);

	//账号文本
	auto userNameLabel = Label::create("账号:", "fonts/FZCY_GBK。ttf", 35);
	userNameLabel->setPosition(plum_blossom->getPositionX() + plum_blossom->getBoundingBox().size.width / 2 + userNameLabel->getBoundingBox().size.height / 2 + 30,
		plum_blossom->getPositionY());
	addChild(userNameLabel);

	//账号输入框
	userNameText = ui::EditBox::create(
		cocos2d::Size(330, 40),
		ui::Scale9Sprite::create("res/denglu11.png"));
	userNameText->setPosition(Vec2(
		userNameLabel->getPositionX() +
		userNameLabel->getBoundingBox().size.width / 2 +
		userNameText->getBoundingBox().size.width / 2 + 20,
		userNameLabel->getPositionY()
	));
	userNameText->setPlaceHolder("请输入你的账号");
	userNameText->setPlaceholderFont("宋体", 25);
	addChild(userNameText);


	//♠
	auto Spade = Sprite::create("res/denglu5.png");
	Spade->setPosition(loginbackground->getPositionX() - loginbackground->getBoundingBox().size.width / 2
		+ plum_blossom->getBoundingBox().size.width + 30, backBtn->getPositionY() - 200);
	addChild(Spade);


	//密码文本
	auto passwordLabel = Label::create("密码:", "fonts/FZCY_GBK。ttf", 35);
	passwordLabel->setPosition(plum_blossom->getPositionX() + plum_blossom->getBoundingBox().size.width / 2 + userNameLabel->getBoundingBox().size.height / 2 + 30,
		plum_blossom->getPositionY()-100);
	addChild(passwordLabel);

	//密码输入框
	passwordText = ui::EditBox::create(
		cocos2d::Size(330, 40), ui::Scale9Sprite::create("res/denglu11.png")
	);
   passwordText->setPosition(Vec2(
		userNameLabel->getPositionX() +
		userNameLabel->getBoundingBox().size.width / 2 +
		userNameText->getBoundingBox().size.width / 2 + 20,
		userNameLabel->getPositionY()-100
	));
	passwordText->setPlaceHolder("请输入你的密码");
	passwordText->setPlaceholderFont("宋体", 25);
	passwordText->setInputFlag(ui::EditBox::InputFlag::PASSWORD);
	addChild(passwordText);

	//记住账号
	auto rememberRadio = CheckBox::create(
		"res/denglu10.png", "res/denglu9.png"
	);
	rememberRadio->setPosition(Vec2(passwordLabel->getPositionX(),
		passwordLabel->getPositionY() - 50
	));
	addChild(rememberRadio);


	//记住账号文本
	auto rememberLabel = Label::createWithTTF(
		"记住账号", "fonts/FZCY_GBK.ttf", 28
	);
	rememberLabel->setPosition(
		rememberRadio->getPositionX() +
		rememberLabel->getBoundingBox().size.width / 2 + 30,
		rememberRadio->getPositionY()
	);
	addChild(rememberLabel);


	//自动登录
	auto autoLoginRadio = CheckBox::create(
		"res/denglu10.png", "res/denglu9.png"
	);
	autoLoginRadio->setPosition(Vec2(
		loginbackground->getPositionX() + 50,
		rememberLabel->getPositionY()
	));
	addChild(autoLoginRadio);

	//自动登录文本
	auto autoLoginLabel = Label::createWithTTF(
		"自动登录", "fonts/FZCY_GBK.ttf", 28
	);
	autoLoginLabel->setPosition(
		autoLoginRadio->getPositionX() +
		autoLoginLabel->getBoundingBox().size.width / 2 + 30,
		autoLoginRadio->getPositionY()
	);
	addChild(autoLoginLabel);

	//注册按钮
	auto regBtn = Button::create("res/denglu6.png");
	regBtn->setPosition(Vec2(
		loginbackground->getPositionX() -
		regBtn->getBoundingBox().size.width / 2 - 50,
		autoLoginLabel->getPositionY() - 60
	));
	addChild(regBtn);

	//登录按钮
	auto loginBtn = Button::create("res/denglu7.png");
	loginBtn->setPosition(Vec2(
		loginbackground->getPositionX() +
		loginBtn->getBoundingBox().size.width / 2 + 50,
		regBtn->getPositionY()
	));
	/*loginBtn->addTouchEventListener(
		CC_CALLBACK_2(LoginPageScene::login, this));*/
	loginBtn->addTouchEventListener(
		CC_CALLBACK_1(LoginPageScene::EnterScene, this));
	addChild(loginBtn);

	

	//logo
	auto logo = Sprite::create("res/logo.png");
	logo->setScale(0.6);
	logo->setPosition(
		loginbackground->getPositionX(),
		loginbackground->getPositionY() +
		loginbackground->getBoundingBox().size.height / 2 +
		logo->getBoundingBox().size.height / 2 + 10
	);
	addChild(logo);


	return true;
}

void LoginPageScene::login(Ref * pSender, Widget::TouchEventType type)
{
	if (type == Widget::TouchEventType::ENDED) {
		auto userName = userNameText->getText();
		auto password = passwordText->getText();
		log(userName);
		log(password);
	}
}

void LoginPageScene::EnterScene(Ref * pSender)
{
	log("aaa");
	Director::getInstance()->replaceScene(Scene0917::createScene());
}

